package com.qf.dao.impl;

import com.qf.dao.AddressDao;
import com.qf.model.Address;
import com.qf.model.Goods;
import com.qf.util.JDBCUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.Connection;
import java.util.List;

public class AddressDaoImpl implements AddressDao {
    QueryRunner qr=new QueryRunner();
    @Override
    public List<Address> selectAddressesByUid(int uid) {
        Connection con=null;
        List<Address> list=null;
        try {
            con= JDBCUtil.getCon();
            //默认只查询上架的商品
            String sql="select * from address where uid=?";
            list = qr.query(con,sql,new BeanListHandler<Address>(Address.class),uid);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            JDBCUtil.colseCon(con);
        }
        return list;
    }

    @Override
    public Address selectAddressById(Integer aid) {
        Connection con=null;
        Address address=null;
        try {
            con= JDBCUtil.getCon();
            //默认只查询上架的商品
            String sql="select * from address where aid=?";
            address = qr.query(con,sql,new BeanHandler<Address>(Address.class),aid);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            JDBCUtil.colseCon(con);
        }
        return address;
    }
}
